;
;
;      ---------========= DSx86 Configuration Editor =========---------
;                               by RyouArashi
;                        http://ryouarashi.blogspot.com
;
;
;              ---------========= License Agreement =========---------
;
;Copyright 2010 RyouArashi. All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;
;   1. Redistributions of source code must retain the above copyright notice,
;      this list of conditions and the following disclaimer.
;
;   2. Redistributions in binary form must reproduce the above copyright notice,
;      this list of conditions and the following disclaimer in the documentation
;      and/or other materials provided with the distribution.
;
;THIS SOFTWARE IS PROVIDED BY RyouArashi ``AS IS'' AND ANY EXPRESS OR IMPLIED
;WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
;EVENT SHALL RyouArashi OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
;INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
;PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
;OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
;ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

global _SetCursorMode;
global _GetCursorMode;
global _InitCursor;

segment _DATA byte public class=DATA
_CursorBackup:
    ; Backup Default Cursor
    dw 0

segment _TEXT byte public class=CODE
; IMPORTANT: These functions assume "Small" memory model!

; void InitCursor()
_InitCursor:
    ; Get Current Cursor Mode
    call near _GetCursorMode

    ; Save to CursorBackup
    mov word [_CursorBackup], ax

    ; Return
    ret

; void SetCursorMode(unsigned Mode)
_SetCursorMode:
    ; Create Stack Frame
    push bp
    mov bp, sp

    ; Get Value (First Param)
    mov cx, [bp+4]

    ; Check for Zero (which is "CursorBackup")
    or cx,cx
    jnz .L1

    ; Get CursorBackup
    mov cx, word [_CursorBackup]

.L1:
    ; Call int 0x10, Function 1: Set Cursor Size
    mov ah, 1
    int 0x10

    ; Leave Frame and Return
    pop bp
    ret

; unsigned GetCursorMode()
_GetCursorMode:
    ; Call int 0x10, Function 3: Get Cursor Size (Page = 0)
    mov ah, 3
    mov bh, 0
    int 0x10

    ; Move Cursor Size to AX
    mov ax, cx

    ; Return
    ret